package com.java110.mall.goods.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.allocationOrder.AllocationOrderProductDto;
import com.java110.intf.goods.IAllocationOrderProductInnerServiceSMO;
import com.java110.mall.goods.dao.IAllocationOrderProductServiceDao;
import com.java110.po.allocationOrderProduct.AllocationOrderProductPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 调拨单内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class AllocationOrderProductInnerServiceSMOImpl extends BaseServiceSMO implements IAllocationOrderProductInnerServiceSMO {

    @Autowired
    private IAllocationOrderProductServiceDao allocationOrderProductServiceDaoImpl;


    @Override
    public int saveAllocationOrderProduct(@RequestBody AllocationOrderProductPo allocationOrderProductPo) {
        int saveFlag = 1;
        allocationOrderProductServiceDaoImpl.saveAllocationOrderProductInfo(BeanConvertUtil.beanCovertMap(allocationOrderProductPo));
        return saveFlag;
    }

    @Override
    public int updateAllocationOrderProduct(@RequestBody AllocationOrderProductPo allocationOrderProductPo) {
        int saveFlag = 1;
        allocationOrderProductServiceDaoImpl.updateAllocationOrderProductInfo(BeanConvertUtil.beanCovertMap(allocationOrderProductPo));
        return saveFlag;
    }

    @Override
    public int deleteAllocationOrderProduct(@RequestBody AllocationOrderProductPo allocationOrderProductPo) {
        int saveFlag = 1;
        allocationOrderProductPo.setStatusCd("1");
        allocationOrderProductServiceDaoImpl.updateAllocationOrderProductInfo(BeanConvertUtil.beanCovertMap(allocationOrderProductPo));
        return saveFlag;
    }

    @Override
    public List<AllocationOrderProductDto> queryAllocationOrderProducts(@RequestBody AllocationOrderProductDto allocationOrderProductDto) {

        //校验是否传了 分页信息

        int page = allocationOrderProductDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            allocationOrderProductDto.setPage((page - 1) * allocationOrderProductDto.getRow());
        }

        List<AllocationOrderProductDto> allocationOrderProducts = BeanConvertUtil.covertBeanList(allocationOrderProductServiceDaoImpl.getAllocationOrderProductInfo(BeanConvertUtil.beanCovertMap(allocationOrderProductDto)), AllocationOrderProductDto.class);

        return allocationOrderProducts;
    }


    @Override
    public int queryAllocationOrderProductsCount(@RequestBody AllocationOrderProductDto allocationOrderProductDto) {
        return allocationOrderProductServiceDaoImpl.queryAllocationOrderProductsCount(BeanConvertUtil.beanCovertMap(allocationOrderProductDto));
    }

    public IAllocationOrderProductServiceDao getAllocationOrderProductServiceDaoImpl() {
        return allocationOrderProductServiceDaoImpl;
    }

    public void setAllocationOrderProductServiceDaoImpl(IAllocationOrderProductServiceDao allocationOrderProductServiceDaoImpl) {
        this.allocationOrderProductServiceDaoImpl = allocationOrderProductServiceDaoImpl;
    }
}
